import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  },
  {
    path: '/PunchCard',
    name: 'PunchCard',
    component: () => import('../views/PunchCard/PunchCard.vue'),
    meta:{title:'打卡页面'},
  },
  {
    path: '/leave',
    name: 'leave',
    component: () => import('../views/Application/leave.vue'),
    meta:{title:'请假申请'}
  },
  {
    path: '/PowerNotes',
    name: 'PowerNotes',
    component: () => import('../views/PowerNotes/PowerNotes.vue'),
    meta:{title:'日程管理'}
  },
  {
    path: '/reissue',
    name: 'reissue',
    component: () => import('../views/Application/reissue.vue'),
    meta:{title:'补卡申请'}
  },
  {
    path: '/evection',
    name: 'evection',
    component: () => import('../views/Application/evection.vue'),
    meta:{title:'我的审核'}
  },
  {
    path: '/audit',
    name: 'audit',
    component: () => import('../views/Audit/Audit.vue'),
    meta:{title:'我的审核'}
  },
  {
    path: '/PowerNotes',
    name: 'PowerNotes',
    component: () => import('../views/PowerNotes/PowerNotes.vue')
  },{
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  }

]

const router = createRouter({
  history: createWebHistory(),
  routes
})
const hei = ['/','/PunchCard','/PowerNotes','/audit','/evection','/reissue']
router.beforeEach((to, from, next) => {
  if(hei.includes(to.path)){
    if(sessionStorage.getItem('vuex')){
        next()
    }else{
        next('/login')
    }
  }else{
      next()
  }
})

export default router
